var app = getApp();
Page({
  /**
   * 页面的初始数据
   */
  data: {
    imgurl: app.urlimg,
    data:"",
    gift_info:"",
    gift_id:"",
    log_id:"",
    istrue:true,
    model:false,
    manager:'luotuosisi',
  },

  formSubmit: function (e) {
    var that = this;
    var user_value = e.detail.value;
    if (user_value.user_name == '') {
      gift('请输入联系人');
      return;
    }
    if (user_value.user_phone == '') {
      gift('请输入电话号码');
      return;
    }
    console.log('省', user_value.user_province);
    console.log('市', user_value.user_city);
    console.log('区', user_value.user_area);
    console.log('详细地址', user_value.user_ruined);
    if (user_value.user_province == '' || user_value.user_city == '' || user_value.user_area == '' || user_value.user_ruined == ''){
      gift('请输入地址');
      return;
    }
    if (user_value.user_editing == '') {
      gift('请输入邮政编码');
      return;
    }
    console.log('礼品文案', user_value.user_gift);


    wx.request({
      url: app.url + 'api_blessing/add_gift_save',
      data: {
        id: that.data.gift_id,
        user_name:user_value.user_name,
        user_phone: user_value.user_phone,
        user_province: user_value.user_province,
        user_city: user_value.user_city,
        user_area: user_value.user_area,
        user_ruined: user_value.user_ruined,
        user_editing: user_value.user_editing,
        user_gift: user_value.user_gift
      },
      header: {
        'content-type': 'application/json',
        'token': wx.getStorageSync('token_key')
      }, success: function (res) {
        if (res.data.done) {
          that.setData({
            model: true
          })
        } else {
          wx.showModal({
            title: '提示',
            content: res.data.message
          })
        }
      }
    })
    function gift(text) {
      //提示信息
      wx.showToast({
        title: text,
        icon: 'loading',
        duration: 1500,
      })
    }
  },

  canle:function(){
    var that=this;
    console.log();
    var model=that.data.model;
    if(model){
      model = false;
      wx.redirectTo({
        url: '../detail/index?id=' + that.data.id,
      })
    }
    that.setData({
      model:model,
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    wx.request({
      url: app.url + 'api_blessing/add_gift',
      data: {
        log_id: options.log_id,
        gift_id: options.gift_id,
      },
      header: {
        'content-type': 'application/json',
        'token': wx.getStorageSync('token_key')
      }, success: function (res) {
        console.log(res.data.result);
        that.setData({
          id: options.id,
          log_id: options.log_id,
          gift_id: options.gift_id,
          data: (res.data.result ? res.data.result : ''),
          gift_info: (res.data.result.gift_info ? res.data.result.gift_info : [] ),
        })
      }
    })


    //猜你喜欢
    wx.request({
      url: app.url + 'api_footprint/footprint_group_list',
      data: {
      },
      header: {
        'content-type': 'application/json',
        'token': wx.getStorageSync('token_key')
      },
      success: function (json) {
        that.setData({
          likegoods: json.data.result,
        })
      }
    })
  },
  // 猜你喜欢列表
  click_goods: function (e) {
    wx.navigateTo({
      url: '/pages/index/detail/index?id=' + e.currentTarget.id,
    })
  },
})